<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>关注回复</title>
<link rel="shortcut icon" type="image/ico"
	href="${basePath}/favicon.ico?v=1" />
<link rel="stylesheet" type="text/css"
	href="${basePath}/css/style-1.css" />
<link rel="stylesheet" type="text/css"
	href="${basePath}/css/style_2_common.css" />
<script type="text/javascript" src="${basePath}/js/jquery-1.8.3.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="${basePath}/js/layer/skin/layer.css" />
<script type="text/javascript" src="${basePath}/js/layer/layer.m.js"></script>
</head>
<body id="nv_member" class="pg_CURMODULE">
	<#assign current='menu_sub'>
	<div id="wp" class="wp">
		<#include "/include/header.html"/>
		<!--中间内容-->
		<div class="contentmanage">
			<div class="developer">
				<div class="tableContent">
					<#include "/include/left.html"/> <#include "/include/wxtop.html"/>
					<div class="content">
						<div class="cLineB">
							<h4 style="font-size: 16px;">
								关注时自动回复内容 <span class="FAQ">可参考右边的范例来写,关注回复文字的信息，回复帮助也是此信息！</span>
							</h4>
						</div>
						<div class="zdhuifu">
							<form method="post" action="${basePath}/admin/sub/persis"
								enctype="multipart/form-data" id="mainForm"
								onsubmit="return checkForm();">
								<input type="hidden" name="id" id="input_id"
									value="${bean.id?default('')}" />
								<table cellspacing="0" cellpadding="0" border="0" width="100%">
									<tr>
										<td height="5"></td>
										<td></td>
									</tr>
									<tr>
										<td valign="top" width="420"><textarea class="px"
												maxlength="2000"
												style="width: 420px; height: 400px; margin: 5px 0; text-align: left;"
												id="Hfcontent" name="content" placeholder="请输入自动回复文本">${bean.content}</textarea>
											<p>
												<input id="checkbox_mul" type="checkbox" value="1"<#if
													bean.isMultipart??&&bean.isMultipart!=0>checked</#if>
													/>我想从资源库中选择 <input id="input_isMultipart" type="hidden"
													value="${bean.isMultipart?default(0)}" name="isMultipart" />
											</p>
											<p id="input_key_com" style="display: none;">
												关键词：<input type="input" style="width: 100px;" class="px"
													id="input_keyword" readonly name="keyword" /> <input
													type="hidden" name="picReplyId" id="input_picReplyId"
													value="${bean.picReplyId?default('')}" /> <a
													href="javascript:void(0)" class="a_choose"
													onclick="makeAChoice();">从资源库选择</a>
											</p></td>
										<td valign="top">
											<div class="zdhuifu" style="margin-left: 20px">
												<h4>参考范例：</h4>
												这里是关注时的回复。
											</div>
										</td>
									</tr>
									<tr>
										<td height="50"><input type="submit" value="保存"
											name="sbmt" class="btnGreen left" /> <#include
											"/include/face.html"/></td>
									</tr>
								</table>
							</form>
						</div>
					</div>
					<div class="clr"></div>
				</div>
			</div>
		</div>
		<!--底部-->

		<div style="display: none;" id="pick_item_com">
			<div style="font-size: 14px; padding: 5px 10px 10px 20px;">
				<div
					style="background: #fefbe4; border: 1px solid #f3ecb9; color: #993300; padding: 10px; margin: 10px auto 5px auto;">
					使用方法：点击对应内容后面的“选中”即可。
					<!-- 您也可以点击 <a href="${basePath}/mul/index">添加多图文回复</a> -->
				</div>
				<table class="ListProduct" border="0" cellspacing="0"
					cellpadding="0" width="100%">
					<thead>
						<tr>
							<th>标题</th>
							<th>类型</th>
							<th style="width: 80px;">操作 <span class="tooltips"></span></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	</div>
	</div>
	<#include "/include/footer.html"/>

	<script type="text/javascript">
		function checkForm() {
			var $content = $("#Hfcontent");
			var $check = $(":checkbox");
			var $isChecked = $(":checkbox:checked");
			if (!$isChecked.length || $isChecked.length < 1) {
				if ($.trim($content.val()) == "") {
					layer.alert("文本回复内容不能为空", {
						icon : 1
					});
					return false;
				}
				return true;
			} else {
				var $keyword = $("#input_keyword");
				if ($keyword.val() == "") {
					layer.alert("请选择回复内容", {
						icon : 1
					});
					return false;
				}
				return true;
			}
			return false;
		}
		function makeAChoice() {
			var dialog = function() {
				var layerIndex = layer.open({
					type : 1,
					area : [ '600px', '450px' ],
					scrollbar : false,
					fix : true,
					title : '请选择资源',
					content : $("#pick_item_com").html()
				});
				return layerIndex;
			}
			var $check = $(":checkbox:checked");
			if (!$check.length && $check.length < 1) {
				layer.confirm("是否勾选多图文标识?", {
					icon : 4,
					title : '确认信息'
				}, function(index) {
					$(":checkbox").attr("checked", "true");
					layer.close(index);
					window.layerIndex = dialog();
				}, function(index) {
					layer.close(index);
					layer.msg("请勾选多图文回复");
				});
			} else {
				window.layerIndex = dialog();
			}
		}
		function pickItem(id, keyword, type) {
			$("#input_keyword").val(keyword);
			$("#input_picReplyId").val(id);
			//回复的类型
			$("#input_isMultipart").val(type);
			layer.close(window.layerIndex);
		}

		function makeData(pageIndex, select) {
			if (!select) {
				select = "#pick_item_com";
			}
			var $tBody = $(select + " table tbody");
			$
					.post(
							"${basePath}/admin/sub/ajax",
							{
								"currentPage" : pageIndex
							},
							function(data) {
								for (var i = 0; i < data.recordList.length; i++) {
									var bean = data.recordList[i];
									var keyword = bean.keyword;
									var id = bean.id;
									var type = bean.type;
									var typeName = "";
									if (type == 4) {
										typeName = "音频回复";
									} else if (type == 3) {
										typeName = "多图文回复";
									} else if (type == 2) {
										typeName = "单图文回复";
									} else if (type == 1) {
										typeName = "文本回复";
									} else if (type == 5) {
										typeName = "图片回复"
									}
									var $tr = $('<tr><td>'
											+ keyword
											+ '</td><td>'
											+ typeName
											+ '</td><td class="norightborder"><a href="javascript:void(0);" onclick="pickItem('
											+ id + ', \'' + keyword + '\', \''
											+ type + '\');">选中</a></td></tr>')
									$tBody.append($tr);
								}
								//分页
								var currentPage = data.currentPage;
								var total = data.total;
								var pages = data.pages;
								var previouspage = data.previouspage;
								var nextpage = data.nextpage;
								var pageText = '<div class="cLine"><div class="pageNavigator right"><div class="pages">共';
								pageText += total + "条记录  ";
								if (pages > 0) {
									pageText += currentPage;
								} else {
									pageText += 0;
								}
								pageText += "/" + pages + "页";
								if (currentPage > 1) {
									pageText += '<a href="javascript:go(1);">首页</a>';
								}
								if (previouspage > 1) {
									pageText += '<a href="javascript:go('
											+ previouspage + ');">上一页</a>';
								}
								if (nextpage < pages) {
									pageText += '<a href="javascript:go('
											+ nextpage + ');">下一页</a>';
								}
								if (currentPage < pages) {
									pageText += '<a href="javascript:go('
											+ pages + ');">最后一页</a>'
								}
								var $table = $(select + " table");
								$table.after(pageText);
							}, 'json');
		}

		function go(pageIndex) {
			$(".layui-layer-content table tbody").html("");
			$(".layui-layer-content table").next().remove();
			makeData(pageIndex, '.layui-layer-content');
		}

		$(function() {
			makeData(1);
			$("#checkbox_mul").click(function() {
				var $comp = $("#input_key_com");
				if (this.checked == true) {
					$comp.show().children("input").each(function() {
						this.value = "";
					});
				} else {
					$comp.hide().children("input").each(function() {
						this.value = "";
					});
					//取消选择设置成文本回复
					$("#input_isMultipart").val("0");
				}
			});

			var type = $("#input_isMultipart").val();
			var id = $("#input_picReplyId").val();
			if (type != 0) {
				$("#input_key_com").show();
				$.post('${basePath}/admin/sub/detail', {
					'type' : type,
					'id' : id
				}, function(data) {
					$("#input_keyword").val(data);
				});
			}
		});
	</script>
</body>
</html>